<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['status']=$this->jiqilog_status;
$tabs=array(
	array('op'=>'list','title'=>'全部记录'),
	array('op'=>'error','title'=>'异常预约'),
); 
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status']) && $_RQ['status']!=100){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
	if($_RQ['mid']){
		$params['mid']=$_RQ['mid'];
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['times']){
		$params['times']=$_RQ['times'];
		$return['params']['times']=$_RQ['times'];
	}
	if($_RQ['dayid']){
		$params['dayid']=$_RQ['dayid'];
		$return['params']['dayid']=$_RQ['dayid'];
	}
	if(!empty($_RQ['goodstitle'])){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['goodstitle']).'%';
		$goodsids=pdo_getall('jy_weishop_goods',$params2,'id','id');
		if($goodsids){
			$goodsids=array_keys($goodsids);
			$pingids=pdo_getall('jy_newping_goods',array('goodsid'=>$goodsids,'uniacid'=>$_SESSION['uniacid']),'id','id');
		}
		if($pingids){
			$pingids=array_keys($pingids);
			$params['pingid']=$pingids;
		}else{
			$params['pingid']=0;
		}
		$return['params']['goodstitle']=$_RQ['goodstitle'];
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_newping_yuyue',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$pinggoods=pdo_get('jy_newping_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pingid']));
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$pinggoods['goodsid']),array('title','image'));
			$item['isaddress']=$item['addressid']?1:0;
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'goods.title','title'=>'拼团商品','type'=>'string'),
			array('name'=>'goods.image','title'=>'拼团商品图片','type'=>'image'),
			array('name'=>'isjiqi','title'=>'预约类型','type'=>'radio','options'=>'jiqi'),
			array('name'=>'isaddress','title'=>'带地址？','type'=>'radio','options'=>'isaddress'),
			array('name'=>'dayid','title'=>'预约日期','type'=>'string'),
			array('name'=>'times','title'=>'预约时间段','type'=>'string'),
			array('name'=>'createtime','title'=>'预约时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'dayid','title'=>'日期','type'=>'string','width'=>15),
			array('name'=>'times','title'=>'时间段','type'=>'string','width'=>15),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string','width'=>15),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		)
	);
	$return['jiqi']=array('手动预约','机器人预约');
	$return['isaddress']=array('无','有地址');
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='error'){
	$return['params']=array();
	$yestime = mktime(0,0,0,date('m'),date('d')-1,date('Y'));
	$params=array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$yestime);
	if(isset($_RQ['status']) && $_RQ['status']!=100){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
	if($_RQ['mid']){
		$params['mid']=$_RQ['mid'];
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['times']){
		$params['times']=$_RQ['times'];
		$return['params']['times']=$_RQ['times'];
	}
	if($_RQ['dayid']){
		$params['dayid']=$_RQ['dayid'];
		$return['params']['dayid']=$_RQ['dayid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getall('jy_newping_yuyue',$params,'','','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$isping=$this->model('model')->che_isping($item['pingid'],$item['mid'],$item['times'],$item['dayid'],$item['uniacid']);
			if($isping){
				unset($list[$k]);
				continue;
			}
			$item['member']=cfc('core')->member_show($item['mid']);
			$pinggoods=pdo_get('jy_newping_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pingid']));
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$pinggoods['goodsid']),array('title','image'));
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'这里显示近两天预约了，但是没有参与拼团的预约信息！','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'goods.title','title'=>'拼团商品','type'=>'string'),
			array('name'=>'goods.image','title'=>'拼团商品图片','type'=>'image'),
			array('name'=>'isjiqi','title'=>'预约类型','type'=>'radio','options'=>'jiqi'),
			array('name'=>'dayid','title'=>'预约日期','type'=>'string'),
			array('name'=>'times','title'=>'预约时间段','type'=>'string'),
			array('name'=>'createtime','title'=>'预约时间','type'=>'time'),
		),'action'=>array(
			//array('type'=>'post','op'=>'jiedong','title'=>'恢复解冻'),
		)),
		'search'=>array(
			array('name'=>'dayid','title'=>'日期','type'=>'string','width'=>15),
			array('name'=>'times','title'=>'时间段','type'=>'string','width'=>15),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		)
	);
	$return['jiqi']=array('手动预约','机器人预约');
	$return['htmls']=$htmls;	
	exi($return);
}
/*if($_RQ['op']=='jiedong'){
	$postdata=get_postdata();
	$data=array(
		'jsjiqi'=>intval($postdata['jsjiqi']),
		'jiqiendtime'=>strtotime($postdata['jiqiendtime']),
		'status'=>intval($postdata['status']),
		'freeze'=>$postdata['freeze'],
	);
	$id=intval($_RQ['id']);
	if(!$id){
		exi('操作失败！','error');
	}
	$yuyue=pdo_get('jy_newping_yuyue',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$this->model('member')->recharge($yuyue['mid'],$yuyue['fee'],3,'手动解冻');
	exi('解冻成功！','','list');
}*/